package data.objects;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBIgnore;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBRangeKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;

import data.dynamodbfunctions.Persistence_Helper_PubThread;
import data.exceptions.Dynamo_DB_Functions_Exception;
import data.meta.Metadata;
import data.meta.MetaAnnotations.MetaMethod;
import data.meta.MetaAnnotations.MetaParam;

/**
 * Ein Froum_Thread Objekt
 * @author Alexander
 *
 */
@DynamoDBTable(tableName="CC_Forum_Thread")
public class PubThread {
		
	public String TenantID;
	public String ID;
	public String ForumID;
	public String ersteller;
	public String admin;
	public String erstelldatum;
	public String beschreibung;
	public String name;
		
	public PubThread(){
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SS");
		Date date = new Date();	
		this.ID = ""+UUID.randomUUID();
		this.erstelldatum = ""+dateFormat.format(date);
	}
		
	
	public PubThread(String forum_id,String tenant_id, String ersteller,
			String admin, String beschreibung,
			String name) {
		super();
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SS");
		Date date = new Date();
		this.ForumID = forum_id;
		this.ID = ""+UUID.randomUUID();
		this.TenantID=tenant_id;
		this.ersteller = ersteller;
		this.admin = admin;
		this.erstelldatum = ""+dateFormat.format(date);
		this.beschreibung = beschreibung;
		this.name = name;
	}


	@DynamoDBHashKey(attributeName="ID")
	public String getForum_id() {return ForumID;}
	public void setForum_id(String forum_id) {this.ForumID = forum_id;}
	
	@DynamoDBRangeKey(attributeName="Range_ID")
	public String getThread_id() {return ID;}
	public void setThread_id(String thread_id) {this.ID = thread_id;}
	
	@DynamoDBAttribute(attributeName="TenantID")
	public String getTenant_id() {return TenantID;}
	public void setTenant_id(String thread_id) {this.TenantID = thread_id;}
	
	@DynamoDBAttribute(attributeName="Ersteller")
	public String getErsteller() {return ersteller;}
	public void setErsteller(String ersteller) {this.ersteller = ersteller;}
	
	@DynamoDBAttribute(attributeName="Admin")
	public String getAdmin() {return admin;}
	public void setAdmin(String admin) {this.admin = admin;}
	
	@DynamoDBAttribute(attributeName="Erstelldatum")
	public String getErstelldatum() {return erstelldatum;}
	public void setErstelldatum(String erstelldatum) {this.erstelldatum = erstelldatum;}
	
	@DynamoDBAttribute(attributeName="Beschreibung")
	public String getBeschreibung() {return beschreibung;}
	public void setBeschreibung(String beschreibung) {this.beschreibung = beschreibung;}
	
	@DynamoDBAttribute(attributeName="Name")
	public String getName() {return name;}
	public void setName(String forumname) {this.name = forumname;}
	
	@DynamoDBIgnore
	public static Metadata getMetaData(){
		Metadata meta= ClassSpy.getMetadata( "data.objects.PubThread");
		return meta;
	}
//	@MetaMethod
	@DynamoDBIgnore
	public static PubThread read(@MetaParam("ForumID") String ForumID, @MetaParam("ID") String id) throws Dynamo_DB_Functions_Exception {
		PubThread readobject=Persistence_Helper_PubThread.getInstance().read(ForumID,id);
		return readobject;
	}
	@MetaMethod
	@DynamoDBIgnore
	public static List<PubThread> read(@MetaParam("TenantID") String TenantID) throws Dynamo_DB_Functions_Exception {
		List<Select_Condition> conditionlist=new ArrayList<Select_Condition>();
		List<PubThread> readobject=Persistence_Helper_PubThread.getInstance().readwithAttributes(TenantID, conditionlist);
		return readobject;
	}
//	@MetaMethod
	@DynamoDBIgnore
	public static PubThread delete(@MetaParam("ForumID") String ForumID, @MetaParam("ID") String id) throws Dynamo_DB_Functions_Exception {
		return Persistence_Helper_PubThread.getInstance().delete(ForumID,id);
	}
//	@MetaMethod
	@DynamoDBIgnore
	public static PubThread update(@MetaParam("ForumID") String ForumID,@MetaParam("ID") String id,
			@MetaParam("tenant_id") String tenant_id, @MetaParam("admin")String admin, @MetaParam("name")String name, 
			@MetaParam("beschreibung") String beschreibung) throws Dynamo_DB_Functions_Exception {
		PubThread updateThread =Persistence_Helper_PubThread.getInstance().read(ForumID,id);
		if(!"".equals(tenant_id)){
			updateThread.setTenant_id(tenant_id);
		}
		if(!"".equals(admin)){
			updateThread.setAdmin(admin) ;
		}
		if(!"".equals(beschreibung)){
			updateThread.setBeschreibung(beschreibung);
		}
		if(!"".equals(name)){
			updateThread.setName(name);
		}	
		return Persistence_Helper_PubThread.getInstance().update(updateThread);
	}
//	@MetaMethod
	@DynamoDBIgnore
	public static PubThread create(@MetaParam("ForumID") String ForumID,@MetaParam("ersteller") String ersteller,
			@MetaParam("tenant_id")String tenant_id,@MetaParam("admin")String admin,
			@MetaParam("beschreibung")String beschreibung,@MetaParam("name")String name)throws Dynamo_DB_Functions_Exception {
		PubThread createThread = new PubThread(ForumID, tenant_id,ersteller, admin, beschreibung, name);
		return Persistence_Helper_PubThread.getInstance().create(createThread);	
	}
}
